**Log file

cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Figures"
clear all
log using Fig5.log, replace

**Figure 5***********
**Robustness main coefficient

clear
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data"
use LPSU_MainSample_Sep2024, replace


sum id
**id goes from 1 to 3,467

gen coef=.
gen se=.

***Set of fixed effects
egen sic1year=group(sic1 year)
qui tabulate sic1year, generate(dsic1year)
egen month_post= group(month post)
qui tabulate month_post, generate(dmonth)
qui tabulate year_around_ipo, generate(deventyear) 


foreach i of num 1/1000 {
set more off
qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if id!=`i' , fe first cluster(id) partial (deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
replace coef = _b[IPO] if id==`i'
replace se=_se[IPO] if id==`i'
}

*
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data\Young data"
save r_1000, replace

foreach i of num 1001/2000 {
set more off
qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if id!=`i' , fe first cluster(id) partial (deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
replace coef = _b[IPO] if id==`i'
replace se=_se[IPO] if id==`i'
}

*
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data\Young data"
save r_2000, replace


foreach i of num 2001/3000 {
set more off
qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if id!=`i' , fe first cluster(id) partial (deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
replace coef = _b[IPO] if id==`i'
replace se=_se[IPO] if id==`i'
}

*
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data\Young data"
save r_3000, replace

foreach i of num 3001/3467 {
set more off
qui xtivreg2 wroa (IPO=instrument) deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth* if id!=`i' , fe first cluster(id) partial (deventyear2 deventyear3 deventyear4 deventyear5 dsic1year* dmonth*)
replace coef = _b[IPO] if id==`i'
replace se=_se[IPO] if id==`i'
}

*
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Data\Young data"
save r_3467, replace

gen t=coef/se
gen p=2 * (1 - normal(t))
keep id coef t p
duplicates drop
sum coef t p
*max p-value 4.0%
*min p-value 2.6%
*mean p-value 3.2%
label var p "p-value"
label var coef "2SLS coeff"
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Data"

bysort id: gen random_number = runiform()
egen new_id = group(random_number)
drop id
rename new_id id
label var id "Firm-attempt id"

save Young_excercise_rep, replace



cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Data"
use Young_excercise_rep, replace

cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Figures"

histogram p, percent xscale(range(0 0.05)) xlab(0(0.005) 0.05) xline(.0260084, lpattern(dash) lcolor(black)) xline(.0400066, lpattern(dash) lcolor(red)) title(2SLS p-value sensitivity) subtitle(Deleting one firm at a time)
graph export "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Figures\Young_p.tif", as(tif) replace
graph export Fig5A.pdf, replace 

histogram coef, percent xscale(range(0.15 0.3)) xlab(0.15(0.03) 0.3) xline(0.219, lpattern(dash) lcolor(black)) xline(0.247, lpattern(dash) lcolor(red)) title(2SLS IPO coeff. sensitivity) subtitle(Deleting one firm at a time)
graph export "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Figures\Young_b.tif", as(tif) replace
graph export Fig5B.pdf, replace 

***Log file
cd "C:\Users\sertsios\Dropbox\LPSU replication package RFS\Replication\Log files\Main Figures"
log close
graphlog using Fig5.log, lspacing(1) replace
